// https://typescript.nuxtjs.org/cookbook/plugins
import { Plugin } from '@nuxt/types'

declare module '@nuxt/types' {
  interface Context {
    $myInjectedFunction(message: string): void
  }
}

const myPlugin: Plugin = (context) => {
  context.$axios.onRequest(_config => {
    // 在请求拦截器中添加授权头
    // @ts-ignore
    _config.headers.Authorization = `Bearer ${context.store.state.token}`
    console.log('onRequest')
  })

  context.$axios.onError(_error => {
    console.log('onError')
  })

  context.$axios.onResponse(_response => {
    console.log('onResponse')
    return _response.data
  })
}


export default myPlugin